package com.hzncc.flowable_diboot.coderule.dto;

import com.diboot.core.binding.query.BindQuery;
import com.diboot.core.binding.query.Comparison;
import com.hzncc.flowable_diboot.coderule.entity.CodeRule;
import lombok.Getter;
import lombok.Setter;
import lombok.experimental.Accessors;

import java.time.LocalDate;
import java.time.LocalDateTime;

/**
* 编码规则 DTO定义
*
* @author MyName
* @version 1.0
* @date 2024-06-28
 * Copyright © MyCorp
*/
@Getter
@Setter
@Accessors(chain = true)
public class CodeRuleDTO extends CodeRule {
private static final long serialVersionUID = 1289281160942604539L;

        /**
        * 流水号长度 起始
        */
        @BindQuery(comparison = Comparison.GE, column = "sequence_length")
        private Long sequenceLengthBegin;

        /**
        * 流水号长度 截止
        */
        @BindQuery(comparison = Comparison.LE, column = "sequence_length")
        private Long sequenceLengthEnd;
        /**
        * 当前流水号 起始
        */
        @BindQuery(comparison = Comparison.GE, column = "current_num")
        private Long currentNumBegin;

        /**
        * 当前流水号 截止
        */
        @BindQuery(comparison = Comparison.LE, column = "current_num")
        private Long currentNumEnd;
        /**
        * 创建时间
        */
        @BindQuery(comparison = Comparison.GE)
        private LocalDateTime createTime;
        /**
        * 创建时间 起始
        */
        @BindQuery(comparison = Comparison.GE, column = "create_time")
        private LocalDate createTimeBegin;

        /**
        * 创建时间 截止
        */
        @BindQuery(comparison = Comparison.LT, column = "create_time")
        private LocalDate createTimeEnd;
        /**
        * 更新时间
        */
        @BindQuery(comparison = Comparison.GE)
        private LocalDateTime updateTime;
        /**
        * 更新时间 起始
        */
        @BindQuery(comparison = Comparison.GE, column = "update_time")
        private LocalDate updateTimeBegin;

        /**
        * 更新时间 截止
        */
        @BindQuery(comparison = Comparison.LT, column = "update_time")
        private LocalDate updateTimeEnd;

        public LocalDate getCreateTimeEnd() {
            if (getCreateTime() != null) {
                return getCreateTime().plusDays(1).toLocalDate();
            }
            if (createTimeEnd != null) {
                return createTimeEnd.plusDays(1);
            }
            return null;
        }
        public LocalDate getUpdateTimeEnd() {
            if (getUpdateTime() != null) {
                return getUpdateTime().plusDays(1).toLocalDate();
            }
            if (updateTimeEnd != null) {
                return updateTimeEnd.plusDays(1);
            }
            return null;
        }

}